package cn.jy.nvr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;
import cn.jy.nvr.domain.APHERESES;
import cn.jy.nvr.domain.APHERESESTask;
import cn.jy.nvr.domain.CollectionCollection;
import cn.jy.nvr.domain.CollectionInstall;
import cn.jy.nvr.domain.CollectionInstallSpace;
import cn.jy.nvr.domain.CollectionPuncture;
import cn.jy.nvr.domain.CollectionSpace;
import cn.jy.nvr.domain.CollectionTimeStandardSetting;
import cn.jy.nvr.domain.CollectionUninstall;
import cn.jy.nvr.domain.PERIODIC;
import cn.jy.nvr.domain.ProviderBaseInfo;
import cn.jy.nvr.domain.QueryCollectionRecord;
import cn.jy.nvr.mapper.APHERESESMapper;
import cn.jy.nvr.mapper.APHERESESTaskMapper;
import cn.jy.nvr.mapper.CollectionCollectionMapper;
import cn.jy.nvr.mapper.CollectionInstallMapper;
import cn.jy.nvr.mapper.CollectionInstallSpaceMapper;
import cn.jy.nvr.mapper.CollectionPunctureMapper;
import cn.jy.nvr.mapper.CollectionSpaceMapper;
import cn.jy.nvr.mapper.CollectionTimeStandardSettingMapper;
import cn.jy.nvr.mapper.CollectionUninstallMapper;
import cn.jy.nvr.mapper.PERIODICMapper;
import cn.jy.nvr.mapper.ProviderBaseInfoMapper;
import cn.jy.nvr.utils.TimeUtils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;



@Controller
public class CollectionRecordController
{
	
	@Autowired
	APHERESESTaskMapper  apheresesTaskMapper;
	
	@Autowired 
	ProviderBaseInfoMapper baseInfoMapper;
	
	@Autowired
	APHERESESMapper apheresesMapper;
	@Autowired
	PERIODICMapper   periodicMapper;
	@Autowired
	CollectionTimeStandardSettingMapper timeStandardSettingMapper;
	@Autowired
	CollectionCollectionMapper collectionCollectionMapper;
	@Autowired
	CollectionInstallMapper collectionInstallMapper;
	@Autowired
	CollectionInstallSpaceMapper  collectionInstallSpaceMapper;
	@Autowired
	CollectionSpaceMapper collectionSpaceMapper;
	@Autowired
	CollectionPunctureMapper collectionPunctureMapper;
	@Autowired
	CollectionUninstallMapper collectionUninstallMapper;
	public  static  Map<String, List<PERIODIC>> map= new HashMap<String, List<PERIODIC>>();
	
	//采浆记录的
	@RequestMapping("display/collectionCollection")
	public String CollectionCollection(HttpServletRequest request,HttpServletResponse response) throws Exception{
		
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  String  collectionTakensMap=request.getParameter("collectionTakens");
		  Map<String,Map<String, String>> mapCollectionTakens= new HashMap<String, Map<String, String>>();
		  if (collectionTakensMap!=null&&!"".equals(collectionTakensMap)) {
			  mapCollectionTakens =  mapper.readValue(collectionTakensMap,Map.class);
		}
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<CollectionCollection> collectionCollectionList=new ArrayList<CollectionCollection>();
		  List<CollectionCollection> resultList = new ArrayList<CollectionCollection>();
		  
			 if(!nowDate.isEmpty()){
					//查询缓存表的方式
					 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					 collectionCollectionList = collectionCollectionMapper.loadCollectionCollectionByQuery(queryCollectionRecord);
				 }
			 
			 if (!mapCollectionTakens.isEmpty()) {
				  for (CollectionCollection apheresesTask : collectionCollectionList) {
						if (apheresesTask.getCollectionCycles()!=null) {
							if (mapCollectionTakens!=null) {
								Map<String, String> map=null;
								if (apheresesTask.getCollectionCycles().equals("2")) {
									map= mapCollectionTakens.get("two");	
								}
								if (apheresesTask.getCollectionCycles().equals("3")) {
									map= mapCollectionTakens.get("three");	
								}
								if (apheresesTask.getCollectionCycles().equals("4")) {
									map= mapCollectionTakens.get("four");	
								}
								if (apheresesTask.getCollectionCycles().equals("5")) {
									map= mapCollectionTakens.get("five");	
								}
								if (apheresesTask.getCollectionCycles().equals("6")) {
									map= mapCollectionTakens.get("six");	
								}
								if (Integer.valueOf(apheresesTask.getCollectionCycles())>6||Integer.valueOf(apheresesTask.getCollectionCycles())<2) {
									resultList.add(apheresesTask);
									continue;
								}
								String  collectionTakensSmall=null;
								String    collectionTakensBig=null;
								if (map!=null&&!map.isEmpty()) {
									collectionTakensSmall = map.get("collectionTakensSmall");
								    collectionTakensBig=map.get("collectionTakensBig");
								    
								    if ((collectionTakensSmall==null||"".equals(collectionTakensSmall)) &&(collectionTakensBig==null||"".equals(collectionTakensBig))) {
								    	resultList.add(apheresesTask);
									}
								  //只有小于的时候
									if (collectionTakensSmall!=null&&!"".equals(collectionTakensSmall)&&collectionTakensBig==null) {
										collectionTakensSmall =   TimeUtils.minToSeconds( collectionTakensSmall);
										String collectionTakens =   apheresesTask.getCollectionTakens();
										if (Integer.valueOf(collectionTakens)<Integer.valueOf(collectionTakensSmall)) {
											resultList.add(apheresesTask);
										}
									}
									
									//只有大于的时候
									if (collectionTakensSmall==null&&collectionTakensBig!=null&&!"".equals(collectionTakensBig)) {
										 collectionTakensBig =  TimeUtils.minToSeconds( collectionTakensBig);
										String collectionTakens =   apheresesTask.getCollectionTakens();
										if (Integer.valueOf(collectionTakens)>Integer.valueOf(collectionTakensBig)) {
											resultList.add(apheresesTask);
										}
									}
									
									if (collectionTakensSmall!=null&&!"".equals(collectionTakensSmall)&&collectionTakensBig!=null&&!"".equals(collectionTakensBig)) {
										collectionTakensSmall =   TimeUtils.minToSeconds( collectionTakensSmall); 
										 collectionTakensBig =  TimeUtils.minToSeconds( collectionTakensBig);
										String collectionTakens =   apheresesTask.getCollectionTakens();
										if (Integer.valueOf(collectionTakens)>Integer.valueOf(collectionTakensBig)
												||Integer.valueOf(collectionTakens)<Integer.valueOf(collectionTakensSmall)) {
											resultList.add(apheresesTask);
										}
									}
									
								}
							}
						}
				}
				 
			}else{
				resultList=collectionCollectionList;
			}
		
			 for (CollectionCollection apheresesTask : resultList) {
			    	String collectionTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getCollectionTakens());
			    	apheresesTask.setCollectionTakens(collectionTakens);
		}
		 
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	
	}
	
	//安装耗材
	
	@RequestMapping("display/collectionInstall")
	public String collectionInstall(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  
		  String installTakensSmall = request.getParameter("installTakensSmall");
		  String installTakensBig = request.getParameter("installTakensBig");
		  
		  
		  
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		 if (installTakensSmall!=null&&!"".equals(installTakensSmall)) {
			  installTakensSmall= TimeUtils.minToSeconds(installTakensSmall);	
			  queryCollectionRecord.setInstallTakensSmall(installTakensSmall);
		}
		 if (installTakensBig!=null&&!"".equals(installTakensBig)) {
			 installTakensBig=TimeUtils.minToSeconds(installTakensBig);
			 queryCollectionRecord.setInstallTakensBig(installTakensBig);
		}
		 
		 
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<CollectionInstall> resultList = new ArrayList<CollectionInstall>();
		  
		 if(!nowDate.isEmpty()){
			//查询缓存表的方式
			 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			 resultList = collectionInstallMapper.loadCollectionInstallByQuery(queryCollectionRecord);
		 }
		 for (CollectionInstall apheresesTask : resultList) {
			    	String installTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getInstallTakens());
			    	apheresesTask.setInstallTakens(installTakens);
		}
		 
		
		
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	//安装耗材后空闲时间
	
	@RequestMapping("display/collectionInstallSpace")
	public String collectionInstallSpace(HttpServletRequest request,HttpServletResponse response) throws Exception{

		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  
		  
		  String installSpaceTakensSmall = request.getParameter("installSpaceTakensSmall");
		  String installSpaceTakensBig = request.getParameter("installSpaceTakensBig");
		  
		  
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		 
		 if (installSpaceTakensSmall!=null&&!"".equals(installSpaceTakensSmall)) {
			 installSpaceTakensSmall=TimeUtils.minToSeconds(installSpaceTakensSmall);
			 queryCollectionRecord.setInstallSpaceTakensSmall(installSpaceTakensSmall);
		} 
		 
		 if (installSpaceTakensBig!=null&&!"".equals(installSpaceTakensBig)) {
			 installSpaceTakensBig=TimeUtils.minToSeconds(installSpaceTakensBig);
			 queryCollectionRecord.setInstallSpaceTakensBig(installSpaceTakensBig);
		} 
		 
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<CollectionInstallSpace> resultList = new ArrayList<CollectionInstallSpace>();
		  
		  
		  
		 if(!nowDate.isEmpty()){
			//查询缓存表的方式
			 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			 resultList = collectionInstallSpaceMapper.loadCollectionInstallSpaceByQuery(queryCollectionRecord);
		 }
		 
		 for (CollectionInstallSpace apheresesTask : resultList) {
			    	
			    	String installSpaceTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getInstallSpaceTakens());
			    	apheresesTask.setInstallSpaceTakens(installSpaceTakens);
		}
		 
		
		
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
		
		
	}
	
	@RequestMapping("display/collectionPuncture")
	public String collectionPuncture(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  
		  
		  String punctureTakensSmall = request.getParameter("punctureTakensSmall");
		  String punctureTakensBig = request.getParameter("punctureTakensBig");
		  
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		
		 
		 if (punctureTakensSmall!=null&&!"".equals(punctureTakensSmall)) {
			 punctureTakensSmall=TimeUtils.minToSeconds(punctureTakensSmall);
			 queryCollectionRecord.setPunctureTakensSmall(punctureTakensSmall);
		} 
		 if (punctureTakensBig!=null&&!"".equals(punctureTakensBig)) {
			 punctureTakensBig=TimeUtils.minToSeconds(punctureTakensBig);
			 queryCollectionRecord.setPunctureTakensBig(punctureTakensBig);
		 } 
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<CollectionPuncture> resultList = new ArrayList<CollectionPuncture>();
		  
		  
		  
		 if(!nowDate.isEmpty()){
			//查询缓存表的方式
			 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			 resultList = collectionPunctureMapper.loadCollectionPunctureByQuery(queryCollectionRecord);
		 }
		 
		 for (CollectionPuncture apheresesTask : resultList) {
			    	String punctureTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getPunctureTakens());
			    	apheresesTask.setPunctureTakens(punctureTakens);
		}
		 
		
		
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("display/collectionSpace")
	public String collectionSpace(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  
		  
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<CollectionSpace> resultList = new ArrayList<CollectionSpace>();
		  
		  
		  
		 if(!nowDate.isEmpty()){
			//查询缓存表的方式
			 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			 resultList = collectionSpaceMapper.loadCollectionSpaceByQuery(queryCollectionRecord);
		 }
		 
		 for (CollectionSpace apheresesTask : resultList) {
			 if (apheresesTask.getSpaceTakens()!=null) {
		    		String spaceTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getSpaceTakens());
		    		apheresesTask.setSpaceTakens(spaceTakens);
				}
		}
		 
		
		
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	@RequestMapping("display/collectionUninstall")
	public String collectionUninstall(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  
		  String uninstallTakensSmall= request.getParameter("uninstallTakensSmall");
		  String uninstallTakensBig= request.getParameter("uninstallTakensBig");
		  
		  
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		 if (uninstallTakensSmall!=null&&!"".equals(uninstallTakensSmall)) {
			 uninstallTakensSmall=TimeUtils.minToSeconds(uninstallTakensSmall);
			 queryCollectionRecord.setUninstallTakensSmall(uninstallTakensSmall);
		 } 
		 
		 if (uninstallTakensBig!=null&&!"".equals(uninstallTakensBig)) {
			 uninstallTakensBig=TimeUtils.minToSeconds(uninstallTakensBig);
			 queryCollectionRecord.setUninstallTakensBig(uninstallTakensBig);
		 } 
		 
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<CollectionUninstall> resultList = new ArrayList<CollectionUninstall>();
		  
		  
		  
		 if(!nowDate.isEmpty()){
			//查询缓存表的方式
			 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			 resultList =collectionUninstallMapper.loadCollectionUninstallByQuery(queryCollectionRecord);
		 }
		 
		 for (CollectionUninstall apheresesTask : resultList) {
			    	
			    	
			    	String uninstallTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getUninstallTakens());
			    	apheresesTask.setUninstallTakens(uninstallTakens);
		}
		 
		
		
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("display/collectionRecord")
	public String Collecting(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 ObjectMapper mapper = new ObjectMapper();
		 
		  String nowDate = request.getParameter("date");
		  String nurses = request.getParameter("nurseList");
		  
		  String installTakensSmall = request.getParameter("installTakensSmall");
		  String installTakensBig = request.getParameter("installTakensBig");
		  
		  String installSpaceTakensSmall = request.getParameter("installSpaceTakensSmall");
		  String installSpaceTakensBig = request.getParameter("installSpaceTakensBig");
		  String punctureTakensSmall = request.getParameter("punctureTakensSmall");
		  String punctureTakensBig = request.getParameter("punctureTakensBig");
		  String uninstallTakensSmall= request.getParameter("uninstallTakensSmall");
		  String uninstallTakensBig= request.getParameter("uninstallTakensBig");
		  String  collectionTakensMap=request.getParameter("collectionTakens");
		  
		  
		  Map<String,Map<String, String>> mapCollectionTakens= new HashMap<String, Map<String, String>>();
		  if (collectionTakensMap!=null&&!"".equals(collectionTakensMap)) {
			  mapCollectionTakens =  mapper.readValue(collectionTakensMap,Map.class);
		}
		  QueryCollectionRecord queryCollectionRecord=new QueryCollectionRecord();
		  List<String> nurseList=new ArrayList<String>();
		  if (nurses!=null&&!"".equals(nurses)) {
			  String nurseStr = new String(nurses.getBytes("ISO-8859-1"),"UTF-8");
			  String[] nurseArray = nurseStr.split(",");
			  for (int i = 0; i < nurseArray.length; i++) {
				  nurseList.add(nurseArray[i]);
			 }
		 }
		 if (installTakensSmall!=null&&!"".equals(installTakensSmall)) {
			  installTakensSmall= TimeUtils.minToSeconds(installTakensSmall);	
			  queryCollectionRecord.setInstallTakensSmall(installTakensSmall);
		}
		 if (installTakensBig!=null&&!"".equals(installTakensBig)) {
			 installTakensBig=TimeUtils.minToSeconds(installTakensBig);
			 queryCollectionRecord.setInstallTakensBig(installTakensBig);
		}
		 
		 if (installSpaceTakensSmall!=null&&!"".equals(installSpaceTakensSmall)) {
			 installSpaceTakensSmall=TimeUtils.minToSeconds(installSpaceTakensSmall);
			 queryCollectionRecord.setInstallTakensSmall(installSpaceTakensSmall);
		} 
		 
		 if (installSpaceTakensBig!=null&&!"".equals(installSpaceTakensBig)) {
			 installSpaceTakensBig=TimeUtils.minToSeconds(installSpaceTakensBig);
			 queryCollectionRecord.setInstallTakensBig(installSpaceTakensBig);
		} 
		 
		 if (punctureTakensSmall!=null&&!"".equals(punctureTakensSmall)) {
			 punctureTakensSmall=TimeUtils.minToSeconds(punctureTakensSmall);
			 queryCollectionRecord.setInstallTakensSmall(punctureTakensSmall);
		} 
		 if (punctureTakensBig!=null&&!"".equals(punctureTakensBig)) {
			 punctureTakensBig=TimeUtils.minToSeconds(punctureTakensBig);
			 queryCollectionRecord.setInstallTakensBig(punctureTakensBig);
		 } 
		 if (uninstallTakensSmall!=null&&!"".equals(uninstallTakensSmall)) {
			 uninstallTakensSmall=TimeUtils.minToSeconds(uninstallTakensSmall);
			 queryCollectionRecord.setInstallTakensSmall(uninstallTakensSmall);
		 } 
		 
		 if (uninstallTakensBig!=null&&!"".equals(uninstallTakensBig)) {
			 uninstallTakensBig=TimeUtils.minToSeconds(uninstallTakensBig);
			 queryCollectionRecord.setInstallTakensBig(uninstallTakensBig);
		 } 
		 
		  queryCollectionRecord.setDate(nowDate);
		  queryCollectionRecord.setNurseList(nurseList);
		  
		  List<APHERESESTask> apheresesList=null;
		  List<APHERESESTask> resultList = new ArrayList<APHERESESTask>();
		  
		  
		  
		 if(!nowDate.isEmpty()){
			//查询缓存表的方式
			 DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			 apheresesList = apheresesTaskMapper.loadAPHERESESTaskByDate(queryCollectionRecord);
		 }
		 
		 if (!mapCollectionTakens.isEmpty()) {
			  for (APHERESESTask apheresesTask : apheresesList) {
					if (apheresesTask.getCollectionCycles()!=null) {
						if (mapCollectionTakens!=null) {
							Map<String, String> map=null;
							if (apheresesTask.getCollectionCycles().equals("2")) {
								map= mapCollectionTakens.get("two");	
							}
							if (apheresesTask.getCollectionCycles().equals("3")) {
								map= mapCollectionTakens.get("three");	
							}
							if (apheresesTask.getCollectionCycles().equals("4")) {
								map= mapCollectionTakens.get("four");	
							}
							if (apheresesTask.getCollectionCycles().equals("5")) {
								map= mapCollectionTakens.get("five");	
							}
							if (apheresesTask.getCollectionCycles().equals("6")) {
								map= mapCollectionTakens.get("six");	
							}
							String  collectionTakensSmall=null;
							String    collectionTakensBig=null;
							if (map!=null) {
								collectionTakensSmall = map.get("collectionTakensSmall");
							    collectionTakensBig=map.get("collectionTakensBig");
							}
							//只有小于的时候
							if (collectionTakensSmall!=null&&!"".equals(collectionTakensSmall)&&collectionTakensBig==null) {
								collectionTakensSmall =   TimeUtils.minToSeconds( collectionTakensSmall);
								String collectionTakens =   apheresesTask.getCollectionTakens();
								if (Integer.valueOf(collectionTakens)<Integer.valueOf(collectionTakensSmall)) {
									resultList.add(apheresesTask);
								}
							}
							
							//只有大于的时候
							if (collectionTakensSmall==null&&collectionTakensBig!=null&&!"".equals(collectionTakensBig)) {
								 collectionTakensBig =  TimeUtils.minToSeconds( collectionTakensBig);
								String collectionTakens =   apheresesTask.getCollectionTakens();
								if (Integer.valueOf(collectionTakens)>Integer.valueOf(collectionTakensBig)) {
									resultList.add(apheresesTask);
								}
							}
							
							if (collectionTakensSmall!=null&&!"".equals(collectionTakensSmall)&&collectionTakensBig!=null&&!"".equals(collectionTakensBig)) {
								collectionTakensSmall =   TimeUtils.minToSeconds( collectionTakensSmall); 
								 collectionTakensBig =  TimeUtils.minToSeconds( collectionTakensBig);
								String collectionTakens =   apheresesTask.getCollectionTakens();
								if (Integer.valueOf(collectionTakens)>Integer.valueOf(collectionTakensBig)
										||Integer.valueOf(collectionTakens)<Integer.valueOf(collectionTakensSmall)) {
									resultList.add(apheresesTask);
								}
							}
							if (Integer.valueOf(apheresesTask.getCollectionCycles())>6) {
								resultList.add(apheresesTask);
							}
						}
					}
			}
			 
		}else{
			resultList=apheresesList;
			
		}
		 
		 for (APHERESESTask apheresesTask : resultList) {
			    	
			    	String installTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getInstallTakens());
			    	apheresesTask.setInstallTakens(installTakens);
			    	
			    	String installSpaceTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getInstallSpaceTakens());
			    	apheresesTask.setInstallSpaceTakens(installSpaceTakens);
			    	
			    	String punctureTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getPunctureTakens());
			    	apheresesTask.setPunctureTakens(punctureTakens);
			    	
			    	String collectionTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getCollectionTakens());
			    	apheresesTask.setCollectionTakens(collectionTakens);
			    	
			    	String uninstallTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getUninstallTakens());
			    	apheresesTask.setUninstallTakens(uninstallTakens);
			    	if (apheresesTask.getSpaceTakens()!=null) {
			    		String spaceTakens = TimeUtils.getInputSecondsOuptMin(apheresesTask.getSpaceTakens());
			    		apheresesTask.setSpaceTakens(spaceTakens);
					}
		}
		 
		
		
		String json = null;
		try {
			json = mapper.writeValueAsString(resultList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("display/collectionChart")
	public String chart(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 String nowDate = request.getParameter("date");
		 String cardId = request.getParameter("cardId");
		 List<PERIODIC> periodicList=new ArrayList<PERIODIC>();
		  periodicList = map.get(nowDate+cardId);
		 if (periodicList!=null&&periodicList.size()>0) {
		 }else {
			 if (nowDate!=null&&nowDate.length()>0&&cardId!=null&&cardId.length()>0) {
			     //通过卡号拿到这个浆员ID
					ProviderBaseInfo providerBaseInfoByCardId = baseInfoMapper.getProviderBaseInfoByCardId(cardId);
					String id = providerBaseInfoByCardId.getID();
					if (id!=null&&!"".equals(id)) {
						//根据ID和日期去拿采浆数据
						APHERESES aphereses=new APHERESES();
						aphereses.setDONOR_ID(id);
						aphereses.setSTART_TIME(nowDate);
						APHERESES  apheresesByIDAndDate = apheresesMapper.loadAPHERESESByIDAndDate(aphereses);
						String machinelogid = apheresesByIDAndDate.getMACHINELOGID();
						//拿到日志号然后去拿周期性数据
						if (machinelogid!=null&&!"".equals(machinelogid)) {
							PERIODIC periodic=new PERIODIC();
							periodic.setMLOGID(machinelogid);
							periodicList=periodicMapper.loadPERIODICByMachineLogId(periodic);
						}
					}
				}
			 map.put(nowDate+cardId, periodicList);
		}
		 
		ObjectMapper mapper = new ObjectMapper();
		String json = null;
		try {
			json = mapper.writeValueAsString(periodicList);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	@RequestMapping("display/collectionTimeSetting")
	public String collectionTimeSetting(HttpServletRequest request,HttpServletResponse response) throws Exception{
		 response.setContentType("text/html");
		 response.setCharacterEncoding("utf-8");
		 String callback = request.getParameter("callback"); 
		 
		 CollectionTimeStandardSetting loadCollectionTimeStandardSetting = timeStandardSettingMapper.loadCollectionTimeStandardSetting();
		 
		ObjectMapper mapper = new ObjectMapper();
		String json = null;
		try {
			json = mapper.writeValueAsString(loadCollectionTimeStandardSetting);
		} catch (JsonProcessingException e1) {
			e1.printStackTrace();
		}

		String retStr = callback + "(" + json + ")";
		try {
			PrintWriter out = response.getWriter();
			out.print(retStr);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}